<?php
/**
 * 护照,记录通过安检的用户信息,主要用于规定$id,$name
 * @author Leo 2010-11-19
 *
 */
class Passport {
	public $id = '';
	public $name = '';
	public $login_time = '';
	public $login_ip = '';
	public $authorized = false;
	private $properties = array ();
	public function __construct($id = '') {
		$this->id = '';
	}
	public function __get($name) {
		if (isset ( $this->properties [$name] )) {
			return $this->properties [$name];
		}
		return null;
	}
	public function __set($name, $value) {
		$this->properties [$name] = $value;
	}
	public function cando($op, $resource, $extra = array()) {
		return ucando ( $op, $resource, $extra, $this->id );
	}
	/**
	 * 等到用户类型(部门,分组,城市,等等)
	 * 
	 * @uses get_user_types filter the arg is empty array
	 * @return array key=>value
	 */
	public function types() {
		return apply_filter ( 'get_user_types', array () );
	}
}
/**
 * 我是谁,意即得到我的信息(护照)
 * 
 * @uses get_current_user filter the arg is a Passport instance
 * @return Passport 我的信息
 */
function whoami($id = '') {
	global $__whoami;
	if (! isset ( $__whoami [$id] )) {
		$whoami = new Passport ( $id );
		$__whoami [$id] = apply_filter ( 'get_current_user', $whoami );
	}
	return $__whoami [$id];
}